<%--
  Created by IntelliJ IDEA.
  User: zhouz
  Date: 2023/12/4
  Time: 15:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form id="form1" action="${pageContext.request.contextPath}/form/add" method="post">
    <input type="text" name="name" id="name"><br>
    <input type="password" name="password" id="password"><br>
    <input type="submit" value="提交" id="submit">
    <%--        <input type="button" value="提交" id="submit">--%>
</form>


<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.7.1.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#form1").submit(function (event) {
            alert("进来了")

            // 阻止form表单默认提交
            event.preventDefault();

            let url = "${pageContext.request.contextPath}/form/add";
            $.post(url, {
                name: $("#name").val(),
                password: $("#password").val()
            }, function (resp) {
                console.log(resp);
            })
        });
    });
</script>

</body>
</html>
